/***************************************************************************
 *   Copyright (C) 2008 by Marco Gulino   *
 *   marco.gulino@gmail.com   *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   51 Franklin Street, Fifth Floor Boston, MA 02110-1301, USA            *
 ***************************************************************************/
#include <QCoreApplication>
#include "filesscanner.h"
#include "qdirinterface.h"
#include "qfileinfointerface.h"
#include <QTextStream>
#include "checksummer.h"

int main(int argc, char *argv[])
{
      QCoreApplication app(argc, argv);
      FilesScanner scanner;
      QTextStream out(stdout);
      QStringList scanDirectories=QCoreApplication::arguments();
      scanDirectories.removeAt(0);
      foreach(QString directory, scanDirectories )
        scanner.addScanDirectory( new QDirInterface(directory) );
      out << "Scanning directories " << scanDirectories.join(",") << endl;
      scanner.scan();
      QFileInfoInterfaceHash candidates = scanner.foundFiles();
      CheckSummer checker(QCryptographicHash::Md4);
      QFileInfoChecksummedHash duplicates=checker.hashChecksummed(candidates);
      foreach(QByteArray md5, duplicates.uniqueKeys() ) {
          out << "Files for md5 " << md5.toHex() << ": " << duplicates.count(md5) << endl;
          foreach(QFileInfoInterface *file, duplicates.values(md5) )
              out << "\t" << file->filePath() << endl;
      }
      return 0;
}

